home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9594 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: yarrina.connect.com.au!usenet
  2. From: Andrew Dalgleish <andrewd@axonet.com.au>
  3. Newsgroups: comp.lang.misc,comp.lang.c,comp.lang.pl1
  4. Subject: Re: GOTO controversy
  5. Date: Tue, 12 Mar 1996 11:23:03 +1000
  6. Organization: Axon Research, Pty Ltd
  7. Message-ID: <3144D1F7.E64@axonet.com.au>
  8. References: <rcshlds.1.000A6705@mailserv.mta.ca> <Dn8pJ8.nqs@emi.net> <4grt4e$8fg@goanna.cs.rmit.EDU.AU> <4hl8mt$4po@newshost.cyberramp.net> <DnwCxp.84C@clw.cs.man.ac.uk> <4hsco0$rj5@hoho.quake.net>
  9. NNTP-Posting-Host: andrew.axonet.com.au
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (Win95; I)
  14.  
  15. gomberg@wcf.com wrote:
  16. > This is goto-free and I think equally clear:>>>------------------------------------------------------------------------------
  17. >   HEV    hev1, hev2, hev3;     /* Event semaphores */
  18. >   HMTX   hmtx;                 /* Mutex semaphore  */
  19. >   void  *ptr;
  20. >   if DosCreateEventSem(0, &hev1, 0, FALSE) then do;
  21. >    if DosCreateEventSem(0, &hev2, 0, FALSE) then do;
  22. >     if DosCreateEventSem(0, &hev3, 0, FALSE) then do;
  23. >      if DosCreateMutexSem(0, &hmtx, 0, FALSE) then do;
  24. >       ptr = malloc(SOME_SIZE)
  25. >       if ptr<>NULL then do;
  26. >          /* Do some stuff here */
  27. >          return TRUE; /* We did okay */ end;
  28. >       DosCloseMutexSem(hmtx);  end;
  29. >      DosCloseEventSem(hev3);  end;
  30. >     DosCloseEventSem(hev2);  end;
  31. >    DosCloseEventSem(hev1);  end;
  32. >   return FALSE;
  33. > And I would assert my code is (1) a lot more PL/1-like and
  34. > (2) a lot easier to understand.
  35.  
  36. 1. I assume you have #define'd "do" and "end" as "{" and "}".
  37. How do you encode "do {...} while(...);" ?
  38. 2. The extra semi-colons after each do & end don't achieve anything.
  39. 3. What does "<>" mean in C ?
  40.  
  41. Otherwise, this is one example where you can remove goto's without loss 
  42. of speed and improve clarity.
  43. This doesn't mean you should never use goto's.
  44.  
  45. -- 
  46. Andrew Dalgleish
  47. Senior Software Engineer
  48. Axon Research, Pty Ltd
  49. 6 Wallace Ave
  50. Toorak, VIC
  51. 3142
  52. AUSTRALIA
  53. Tel:    +61-3-9826-5538
  54. Fax:    +61-3-9824-0083
  55. Email:    andrewd@axonet.com.au
  56.